// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import axios from 'axios'
import CommonLogo from './components/CommonLogo.vue'
import CommonTitle from './components/CommonTitle.vue'
import CommonBanner from './components/CommonBanner.vue'
import CommonBottom from './components/CommonBottom.vue'
import UserHeader from './components/UserHeader.vue'
import Loading from './components/Loading.vue'
import Utils from './utils/utils.js'
import CommonConst from './utils/const.js'

Vue.config.productionTip = false;
/***
 * 注册全局组件
 */
Vue.component("CommonLogo", CommonLogo);
Vue.component("CommonTitle", CommonTitle);
Vue.component("CommonBanner", CommonBanner);
Vue.component("CommonBottom", CommonBottom);
Vue.component("UserHeader", UserHeader);
Vue.component("Loading", Loading);
Vue.use(ElementUI);

/***
 * 服务器地址，和本机地址常量
 * @type {{BASE_URL, LOCAL_URL}}
 */
Vue.prototype.CommonConst = CommonConst;
Vue.prototype.Utils = Utils;
Vue.prototype.$http = axios;

/***
 * 配置一些请求过滤器
 */
axios.defaults.baseURL = CommonConst.BASE_URL;
axios.interceptors.request.use(function (config) {
  config.data = JSON.stringify(config.data);
  config.headers = {
    "Content-Type": "application/x-www-form-urlencoded"
  };
  let token = localStorage.getItem("access_token");
  if (token) {
    let obj = {
      "access_token": token
    };
    config.params = Object.assign(obj, config.params);
  }
  return config;
}, function (error) {
  return Promise.reject(error);
});

// Add a response interceptor
axios.interceptors.response.use(function (response) {
  return response;
}, function (error) {
  // Do something with response error
  return Promise.reject(error);
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: {App},
  template: '<App/>'
})
